import { BaseCommand } from '../types/common.interface';
import { TableDatas } from '../cors/table-datas';

export class ValueCommand extends BaseCommand {
    protected oldValue: any = null;
    protected oldType: any = null;
    constructor(
        protected row: number, 
        protected col: number, 
        protected datas: TableDatas,
        protected value: any, 
        protected type: string) {
        super();
    }
    public execute() {
        let cellInstance = this.datas.getRow(this.row).getCell(this.col);
        this.oldValue = cellInstance.value;
        this.oldType = cellInstance.type;
        cellInstance.value = this.value;
        cellInstance.type = this.type;
        this.datas.setCell(this.row, this.col, cellInstance);
        return true;
    }
    public redo() {
        let cellInstance = this.datas.getRow(this.row).getCell(this.col);
        cellInstance.value = this.oldValue;
        cellInstance.type = this.oldType;
        this.datas.setCell(this.row, this.col, cellInstance);
        return true;
    }
}